<?php 

class HolidayController extends BaseController {

	// Table
	public $table = 'holiday';

	// Eloquent Model
	public $model = 'Holiday';

	// Base Route
	public $base = 'holiday';

	// Localization
	public $local = 'en';

	// Language Name
	public $language = 'holiday';

	// Breadcrumbs
	public $breadcrumbs = [ ['link' => 'holiday' , 'title' => 'Holiday'] ];
	
	// Set List Data - Input, Object
	public function setListData($data, $object) {
		//echo $data['filter_date'];
		if( !empty( $data['filter_description'] ) )
			$object=$object->where('description','LIKE','%'.$data['filter_description'].'%');
		
		if( !empty($data['filter_date'] ) ){
			
			$object=$object->where('date','LIKE','%'.$data['filter_date'].'%');
			
		}
		
		return $object;
	}
	// Process before updating data
	public function preStore( $data ) {
			$this->rules = array(
			'description' => 'required',
			'date' => 'required'
			);

		return $data;
	}
	
	public function postStore( $data, $object ) {
		
		$object->description=$data['description'];
		$object->date=$data['date'];
		$object->save();
		
		return $data;
	}
		
	// Process before updating data
	public function preUpdate( $data ) {
		$this->rules = array(
				'description' => 'required',
				'date' => 'required'
		);
	
		return $data;
	}
	
	public function postUpdate( $data, $object ) {
	
		$object->description=$data['description'];
		$object->date=$data['date'];
		$object->save();
	
		return $data;
	}
	
	
	
}
